﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using ProtoBuf;
using SharpDX;
using KDTrees;

namespace Engine
{

    [ProtoContract]
    public class HardPoint
    {
        [ProtoMember(1)]
        public string HPName = "HP_test";
        [ProtoMember(2)]
        public Vector3 LocalPosition = new Vector3();
        [ProtoMember(3)]
        public Vector3 LocalRotation = new Vector3(0, 0, 0);
        [ProtoMember(4)]
        public Matrix Transformation;
    }
    namespace Serialize
    {
        [ProtoContract]
        public class Material
        {
            [ProtoMember(1)]
            public string MaterialName = "null";
            [ProtoMember(2)]
            public string Shader = "Content/Shaders/BaseShader";
            [ProtoMember(3)]
            public string Diffuse = "Content/Textures/Def_diff";
            [ProtoMember(4)]
            public string UV2Diffuse = "Content/Textures/Def_occl";
            [ProtoMember(5)]
            public string NormalMap = "Content/Textures/Def_norm";
            [ProtoMember(6)]
            public string SpecularMap = "Content/Textures/Def_spec";
            [ProtoMember(7)]
            public string SelfMap = "Content/Textures/Def_light";
            [ProtoMember(8)]
            public Vector3 DiffuseMultipler = new Vector3(1, 1, 1);
            [ProtoMember(9)]
            public Vector3 SpecularMultipler = new Vector3(1, 1, 1);
            [ProtoMember(10)]
            public Vector3 SelfMultipler = new Vector3(1, 1, 1);
            [ProtoMember(11)]
            public bool DoubleSide = false;
            [ProtoMember(12)]
            public int Alpha = 0;
        }

        [ProtoContract]
        public class MeshesContainer
        {
            [ProtoMember(1)]
            public string LOONode = "";
            [ProtoMember(2)]
            public Material[] Materials = new Material[0];
            [ProtoMember(3)]
            public HardPoint[] HardPoints = new HardPoint[0];
            [ProtoMember(4)]
            [XmlIgnore]
            public GeometryData Geometry = new GeometryData();
        }

        [ProtoContract]
        public class MeshLink
        {
            [ProtoMember(1)]
            public int StartIndex = 0;
            [ProtoMember(2)]
            public int IndexCount = 0;
            [ProtoMember(3)]
            public Vector3 AABBMax = new Vector3();
            [ProtoMember(4)]
            public Vector3 AABBMin = new Vector3();
        }

        [ProtoContract]
        public class GeometryData
        {
            [ProtoMember(1)]
            public int FormatType = 0;
            [ProtoMember(2)]
            public int VertexCount = 0;
            [ProtoMember(3)]
            public byte[] VertexData;
            [ProtoMember(4)]
            public byte[] IndexData;
            [ProtoMember(5)]
            public MeshLink[] Meshes = new MeshLink[0];
            [ProtoMember(6)]
            public Vector3 AABBMax = new Vector3();
            [ProtoMember(7)]
            public Vector3 AABBMin = new Vector3();
            [ProtoMember(8)]
            public MeshKDTree BSP = null;
        }

        [ProtoContract]
        public class Mesh
        {
            [ProtoMember(1)]
            public int FormatType = 0;
            [ProtoMember(2)]
            public int FaceCount = 0;
            [ProtoMember(3)]
            public int VertexCount = 0;
            [ProtoMember(4)]
            public byte[] VertexData;
            [ProtoMember(5)]
            public byte[] IndexData;
            [ProtoMember(6)]
            public Vector3 AABBMax = new Vector3();
            [ProtoMember(7)]
            public Vector3 AABBMin = new Vector3();
        }
        [ProtoContract]
        public class PhysMesh
        {
            [ProtoMember(1)]
            public Vector3[] Vertex;
            [ProtoMember(2)]
            public int[] Indices;
            [ProtoMember(3)]
            public Vector3 AABBMax = new Vector3();
            [ProtoMember(4)]
            public Vector3 AABBMin = new Vector3();
            public string Name = "";
        }
    }
}
